package com.quantdo.apex.elasticjob.service.impl;

import com.quantdo.apex.elasticjob.constant.ClearsnapshotBean;
import com.quantdo.apex.elasticjob.constant.Constants;
import com.quantdo.apex.elasticjob.model.Response;
import com.quantdo.apex.elasticjob.service.SnapshotService;
import com.quantdo.apex.elasticjob.util.HttpClientUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * @author chenkuan
 * @version v1.0
 * @desc 定时快照处理服务
 * @date 2019/12/12 012 17:30
 */
@Service
public class SnapshotServiceImpl implements SnapshotService {

	private Logger logger = LoggerFactory.getLogger(getClass());

	@Override
	public void snapshot(ClearsnapshotBean snapshotBean) {
		for (String serverIp : snapshotBean.getServerIp().split(Constants.SIGN_1)) {
			StringBuilder builder = new StringBuilder();
			builder.append(snapshotBean.getHeader());
			builder.append(serverIp);
			builder.append(snapshotBean.getContextPath() == null ? "" : snapshotBean.getContextPath());
			builder.append(snapshotBean.getServiceUrl());
			Response<String> response = HttpClientUtil.sendGet(builder.toString());
			if (!response.isSuccess()) {
				logger.warn("server:{} -- 快照接口请求失败", builder.toString());
			}
		}
	}
}
